package com.mayuhao.studentmanage.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.mayuhao.studentmanage.entity.CssStuChoose;
import com.mayuhao.studentmanage.entity.CssStudentVO;
import com.mayuhao.studentmanage.service.ICssStudentService;
import com.mayuhao.studentmanage.util.Result;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 马宇豪
 * @since 2022-10-26
 */
@RestController
//@RequestMapping("/css-student")
public class CssStudentController {
    @Resource
    private ICssStudentService studentService;

    /**
     * @return com.baomidou.mybatisplus.extension.plugins.pagination.Page<CssCourseVO>
     * @description 请修改方法描述
     * @methodName findPage
     * @params [pageNum, pageSize, searchId, searchName]
     * @paramType [java.lang.Integer, java.lang.Integer, java.lang.String, java.lang.String]
     * @author 马宇豪
     * @date 2022/10/26 0026 下午 9:07
     * @email 1757442521@qq.com
     **/
    @GetMapping("/findpage")
    public Page<CssStudentVO> findPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "7") Integer pageSize,
            @RequestParam(defaultValue = "") String searchId,
            @RequestParam(defaultValue = "") String searchName) {
        return studentService.findPage(pageNum, pageSize, searchId, searchName);
    }

    @DeleteMapping("/delsingle/{id}")
    public Result deleteAdmin(@PathVariable Integer id) {
        return new Result(true, "ok", studentService.removeById(id));
    }

    @DeleteMapping("/msdelsingle/{id}")
    public Result deleteMs(@PathVariable Integer id) {
        return new Result(true, "ok", studentService.removeId(id));
    }


    @GetMapping("/findallpage")
    public Page<CssStudentVO> findAllPage(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "7") Integer pageSize,
            @RequestParam(defaultValue = "") String searchId,
            @RequestParam(defaultValue = "") String searchName) {
        return studentService.findAllPage(pageNum, pageSize, searchId, searchName);
    }

    @DeleteMapping("/delbatch/{ids}")
    public boolean deleteAdmin(@PathVariable List ids) {
        return studentService.removeBatchByIds(ids);
    }

    @DeleteMapping("/msdelbatch/{ids}")
    public boolean deleteMs(@PathVariable List<Integer> ids) {
        return studentService.removeBatchIds(ids);
    }


    @GetMapping("/export")
    public void export(HttpServletResponse response) throws IOException {

        studentService.export(response);
    }

    @GetMapping("/findstuid")
    public Result getId() {
        return new Result(true, "ok", studentService.list());
    }

    @PostMapping("/import")
    public void imp(MultipartFile file) throws Exception {
        studentService.imp(file);
    }

    @GetMapping("/hasexport")
    public void hasExport(HttpServletResponse response) throws IOException {

        studentService.hasExport(response);
    }

    @PostMapping("/hasimport")
    public void hasImp(MultipartFile file) throws Exception {
        studentService.hasImp(file);
    }

    @PostMapping("/saveperson")
    public Result savePerson(@RequestBody CssStuChoose cssStuChoose) {
        return new Result(true, "ok", studentService.savePerson(cssStuChoose));
    }

    @PutMapping("/updateperson")
    public Result updatePerson(@RequestBody CssStuChoose cssStuChoose) {

        return new Result(true, "ok", studentService.updatePerson(cssStuChoose));
    }
}
